import Vue from 'vue'
import App from './App'
import store from './store'
import VeeValidate, { Validator } from 'vee-validate'
import config from './common/config'

/*
 * 加载vee验证器
 */
Vue.use(VeeValidate, {
  locale: 'zn_CN',
  errorBagName: 'errorBags', // change if property conflicts.
  fieldsBagName: 'fieldBags',  
});
Validator.extend('mobile', {
    messages: {
      zn_CN:field => field + '请输入正确手机号码',
    },
    validate: value => {
      return value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
    }
});

Vue.config.productionTip = false;

Vue.prototype.$store = store
Vue.prototype.$backgroundAudioData = {
    playing: false,
    playTime: 0,
    formatedPlayTime: '00:00:00'
}

var gqluni = require('./common/unigraph');

var GraphQL = gqluni.GraphQL;

var gql = GraphQL(
    {
        //设置全局url
        url: config.graphql, // url必填
        //设置全居动态header
        header: function () {
            return {
                // something....
                'X-Test-Header': 'test header content'
            }
        },
        //设置全居错误拦截
        errorHandler: function (res) {
            //do something
        }
    }, true
);    
/*
 * 挂载全局变量
 */
Vue.prototype.config = config;       //config变量
Vue.prototype.graphql = gql;         //graphql对象
Vue.prototype.gql_str = "";          //graphql查询文本
Vue.prototype.gql_var = {};          //graphql变量

App.mpType = 'app'

const app = new Vue({
    store,
    ...App
})
app.$mount()